package com.itheima.day01.demo1;

import java.io.Serializable;

public class ArraysUtils {

    private ArraysUtils() {
    }

    //    String toString[int[] arrs
    public static String toString(int[] arrs) {
        if (arrs == null) {
            return null;
        }
        String str="[";
        for (int i = 0; i < arrs.length; i++) {
            str+= (i == arrs.length - 1 ? arrs[i] : arrs[i] + ",");
        }
        str+="]";
        return str;
    }

    //double getAerage[double[] dous
    public static double getAerage(double[] dous) {
        if (dous.length>=3) {
            double max=dous[0];
            double min=dous[0];
            double sum=0;

            for (int i = 0; i < dous.length; i++) {
                if (dous[i] > max) {
                    max=dous[i];
                }

                if (dous[i] < min) {
                    min=dous[i];
                }

                sum+=dous[i];
            }

            double avg = (sum - max - min) / (dous.length - 2);
            return avg;
        } else {
            return 0.0;
        }
    }
}
